package com.qst.rongxiaotong.service.serviceImpl;

import com.qst.rongxiaotong.context.BaseContext;
import com.qst.rongxiaotong.mapper.ShoppingCartMapper;
import com.qst.rongxiaotong.pojo.ShoppingCart;
import com.qst.rongxiaotong.pojo.ShoppingModel;
import com.qst.rongxiaotong.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {
    @Autowired
    ShoppingCartMapper shoppingCartMapper;




    @Override
    public ShoppingCart add(ShoppingCart shoppingCart) {
        shoppingCartMapper.add(shoppingCart);
        return null;
    }

    @Override
    public int delete(Integer id) {
        shoppingCartMapper.delete(id);
        return 0;
    }

    @Override
    public void update(ShoppingCart shoppingcart) {
        shoppingCartMapper.update(shoppingcart);
    }

    @Override
    public List<ShoppingModel> selectByUsername() {
        String name = BaseContext.getCurrentuserName();
        ShoppingCart shoppingCart = new ShoppingCart()
                .setOwnName(name);
        List<ShoppingModel> shoppingModels = shoppingCartMapper.selectByUsername(shoppingCart);

        return shoppingModels;
    }
}
